<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('课程列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>标题：</label>
                            <input type="text" name="title"/>
                            <input type="hidden" id="coursePackageId" name="coursePackageId" th:value="${id}"/>
                        </li>

                        <li>
                            <label>类型：</label>
                            <select id="typeName" name="type" class="form-control m-b"
                                    th:with="type=${@dict.getType('course_package_type')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <input type="hidden" id="age" name="age"/>
                            <div id="age_1">
                                <label>月龄：</label>
                                <select id="age_1_val"  class="form-control m-b"
                                        th:with="type=${@dict.getType('tc_month')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </div>

                            <div id="age_2">
                                <label>月龄：</label>
                                <select id="age_2_val"  class="form-control m-b"
                                        th:with="type=${@dict.getType('tc_family_month')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </div>


                            <div id="age_3">
                                <label>月龄：</label>
                                <select id="age_3_val"  class="form-control m-b"
                                        th:with="type=${@dict.getType('tc_group_month')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </div>

                        </li>
                        <li>
                            <input type="hidden" id="face" name="params[face]"/>
                            <div id="type_2_1">
                                <label>面向：</label>
                                <select id="type_2_1_val" name="type_2_1_val" class="form-control m-b"
                                        th:with="type=${@dict.getType('tc_face')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </div>
                            <div id="type_2_2">
                                <label>面向：</label>
                                <select id="type_2_2_val" class="form-control m-b"
                                        th:with="type=${@dict.getType('tc_family_face')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </div>
                        </li>

                        <li>
                            <input type="hidden" id="week" name="params[week]"/>
                            <div id="type_1_1">
                                <label>周次：</label>
                                <select id="type_1_1_val" name="type_1_1_val" class="form-control m-b"
                                        th:with="type=${@dict.getType('tc_week')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </div>


                            <!--                家庭-->
                            <div id="type_1_1_2">
                                <label>周次：</label>
                                <select id="type_1_1_2_val" class="form-control m-b"
                                        th:with="type=${@dict.getType('tc_family_week')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </div>

                            <!--            群体-->
                            <div id="type_1_1_3">
                                <label>周次：</label>
                                <select id="type_1_1_3_val" class="form-control m-b"
                                        th:with="type=${@dict.getType('tc_group_week')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </div>

                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm"  onclick="register()" ><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <input type="file" name="upload" id="upload" style="display: none;" />
        <input type="hidden" name="id" id="id" style="display: none;" />
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="add()"  >
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" >
                <i class="fa fa-remove"></i> 删除
            </a>
<!--            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:course:export">-->
<!--                <i class="fa fa-download"></i> 导出-->
<!--            </a>-->
            <a class="btn btn-info" onclick="$.table.importExcel()">
                <i class="fa fa-upload"></i> 导入
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "system/course";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            importUrl: prefix + "/importData",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "课程",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'ID',
                },
                {
                    field: 'title',
                    title: '标题'
                },
                {
                    field: 'indexInPackage',
                    title: '显示顺序'
                },
                {
                    field: 'ageLow',
                    title: '月龄 低限'
                },
                {
                    field: 'ageHigh',
                    title: '月龄 高限'
                },
                {
                    field: 'type',
                    title: '类型名称',
                    formatter: function(value, item, index) {
                        return typeName(item.type);
                    }
                },
                {
                    field: 'durations',
                    title: '时长'
                },
                {
                    field: 'created',
                    title: '创建时间'
                },
                {
                    field: 'createdName',
                    title: '创建人'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs  " href="javascript:void(0)" onclick="courseContent(\'' + row.id + '\')"></i>课程详情</a> ');
                        actions.push('<a class="btn btn-warning btn-xs  " href="javascript:void(0)" onclick="courseContentV2(\'' + row.id + '\')"></i>教保指引</a> ');
                        actions.push('<a class="btn btn-success btn-xs  " href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>课程编辑</a> ');
                        actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="updateUser(\'' + row.id + '\')">修改记录</a> ');
                        actions.push('<a class="btn btn-danger btn-xs  " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
        getType();
    });
    function add() {
        var coursePackageId = $('#coursePackageId').val();
        var url = prefix+ '/add?coursePackageId=' + coursePackageId;
        $.modal.open("添加", url);
    }

    function courseContent(id) {
        var url =  '/system/courseContent/courseList?courseId=' + id;
        $.modal.openTab("课程详情", url);
    }

    function courseContentV2(id) {
        var url = '/system/courseContent/courseListV2?courseId=' + id;
        $.modal.openTab("教保指引", url);
    }
    function updateUser(id) {
        var url = '/system/vendorCourseUserRecord?vendorCourseId=' + id;
        $.modal.openTab("修改记录", url);
    }

    function onFile(id) {
        $('#id').val(id);
        $('#upload').click();
    }
    $('#upload').on('change', function(){
        var farmdate = new FormData();
        farmdate.append("file",$('#upload')[0].files[0]);
        farmdate.append("id",$('#id').val());
        $.ajax({
            type:"post",
            url:prefix+"/importImg",
            data:farmdate,
            contentType:false,
            processData:false,
            success:function (date) {
                $.modal.alertSuccess("添加成功")
                $.table.refresh();
            }
        })
    });

    $("#typeName").change(function(){
        getType();
    });

    function register() {
        if ( getType()){
            $.table.search();
        }
    }

    function typeName(type) {
        var content = "";
        if (type == 0) {
            content = '<span class="label label-success">机构端</span>';
        }
        if (type == 1) {
            content = '<span class="label label-primary">家庭端</span>';
        }
        if (type  == 2) {
            content = '<span class="label label-warning">小群体课程</span>';
        }
        return content;
    }

    function getType() {
        var type =  $("#typeName").val();
        //机构端
        if (type == 0) {
            //查询赋值
            $("#age").val($("#age_1_val").val());
            $("#face").val($("#type_2_1_val").val()+"\"");
            $("#week").val($("#type_1_1_val").val()+"\"");

            $("#type_1_1").attr("style", "display:block;");//显示div
            $("#type_1_2").attr("style", "display:block;");//显示div
            $("#type_2_1").attr("style", "display:block;");//显示div
            $("#age_1").attr("style", "display:block;");//显示div

            $("#type_2_2").attr("style", "display:none;");//隐藏div
            $("#type_1_1_3").attr("style", "display:none;");//隐藏div
            $("#type_1_1_2").attr("style", "display:none;");//隐藏div
            $("#age_2").attr("style", "display:none;");//隐藏div
            $("#age_3").attr("style", "display:none;");//隐藏div
            $("#type_1_1_3_val").val("");//给空值
            $("#typ_1_1_2_val").val("");//给空值
            $("#type_2_2_val").val("");//给空值

            return true;
        }
        //家庭端
        if (type == 1) {

            //查询赋值
            $("#age").val($("#age_2_val").val());
            $("#face").val($("#type_2_2_val").val()+"\"");
            $("#week").val($("#type_1_1_2_val").val()+"\"");

            $("#type_1_1").attr("style", "display:none;");//隐藏div
            $("#type_1_2").attr("style", "display:none;");//隐藏div
            $("#type_2_1").attr("style", "display:none;");//隐藏div
            $("#type_1_1_3").attr("style", "display:none;");//隐藏div
            $("#age_1").attr("style", "display:none;");//隐藏div
            $("#age_3").attr("style", "display:none;");//隐藏div
            $("#type_1_1_val").val("");//给空值
            $("#type_1_2_val").val("");//给空值
            $("#type_2_1_val").val("");//给空值
            $("#type_2_1_val").val("");//给空值

            $("#type_2_2").attr("style", "display:none;");//隐藏div
            $("#type_2_2").attr("style", "display:block;");//显示div
            $("#type_1_1_2").attr("style", "display:block;");//显示div
            $("#age_2").attr("style", "display:block;");//隐藏div
            return true;
        }
        //小群体课
        if (type == 2) {
            //查询赋值
            $("#age").val($("#age_3_val").val());
            $("#face").val('');
            $("#week").val($("#type_1_1_3_val").val()+"\"");

            $("#type_1_1").attr("style", "display:block;");//显示div
            $("#type_1_2").attr("style", "display:block;");//显示div
            $("#type_1_1_3").attr("style", "display:block;");//显示div
            $("#age_3").attr("style", "display:block;");//显示div

            $("#type_1_1_2").attr("style", "display:none;");//隐藏div
            $("#type_2_1").attr("style", "display:none;");//隐藏div
            $("#type_2_2").attr("style", "display:none;");//隐藏div
            $("#type_1_1").attr("style", "display:none;");//隐藏div
            $("#age_1").attr("style", "display:none;");//隐藏div
            $("#age_2").attr("style", "display:none;");//隐藏div

            $("#type_2_1_val").val("");//给空值

            return true;
        }
    }


</script>

<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                &nbsp; <a th:href="@{/file/course.xlsx}" download="course.xlsx" class="btn btn-default btn-xs"><i
                    class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</body>
</html>